﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NHTrace
{
  public class SqlParameterReplacer
  {
    public string ReplaceParameters(string statement, Dictionary<string, string> parameters)
    {
      int index = statement.IndexOf(";@p");

      if (index >= 0)
      {
        var aux = statement.Substring(0, index + 1);
        for (int i = parameters.Keys.Count - 1; i >= 0; i--) //backwards, so first we replace @p10, @p11, etc... and last @p1, etc..
        {
          var key = parameters.Keys.ElementAt(i);
          aux = aux.Replace(key, parameters[key]);
        }

        return aux;
      }
      else
        return statement;
    }
  }
}
